<div class="modal-header">
	<button type="button" class="close" data-dismiss="modal" aria-label="Close">
		<span aria-hidden="true">&times;</span>
	</button>
	<h5 class="modal-title" id="addModalLabel">添加</h5>
</div>

            <form id="addForm" role="form" class="form-horizontal parsley-form" data-parsley-validate
                  action="${base}/platform/resource/addDo" method="post">
                  <div class="modal-body">
                <div class="row mb10">
                    <div class="col-lg-12">
                        <div class="form-group">
                            <label for="title" class="col-sm-2 control-label">标题</label>

                            <div class="col-sm-8">
                                <input type="text" id="title" class="form-control" name="title"  placeholder="标题"  required="required">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="remark" class="col-sm-2 control-label">简介</label>

                            <div class="col-sm-8">
                                <input type="text" id="remark" class="form-control" name="remark"  placeholder="简介"  required="required">
                            </div>
                        </div>
                    	<div class="form-group">
                        	<label for="img" class="col-sm-2 control-label">图像</label>

                            <div class="col-sm-8">
                            	<div id="img_queue"></div>
                                <div>
                                	<input id="img_file_upload"  type="file" multiple="false">
                                </div>
                                <div id="img_img" style="padding: 5px;"></div>
                                <input type="hidden" id="img" name="img" value="" >
                           	</div>
                       	</div>
                        <div class="form-group">
                            <label for="link" class="col-sm-2 control-label">链接</label>

                            <div class="col-sm-8">
                                <input type="text" id="link" class="form-control" name="link" required="required" placeholder="链接">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="location" class="col-sm-2 control-label">排序</label>

                            <div class="col-sm-8">
                                <input type="text" id="location" class="form-control" name="location" required="required" placeholder="排序"  data-parsley-type="number">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="state" class="col-sm-2 control-label">状态</label>

                            <div class="col-sm-8">
                                 <input type="radio" name="state" required="required" value="0"  />启用
                                 <input type="radio" name="state" required="required" value="1"  />禁用
                            </div>
                        </div>
                    </div>
                </div>
                </div>
				<div class="modal-footer">
					<button  class="btn btn-default btn-sm btn-parsley" >完成</button> 
				</div>
            </form>
<script language="JavaScript">

	function img_clearFile() {
	    $("#img_img").html("");
	    $("#img_queue").html("");
	    $("#img").val("");
	}
    $(document).ready(function () {
    	$('#img_file_upload').uploadifive({
            'auto': true,
            'multi': false,
            'width': '100%',
            'height': '35',
            'buttonText': '请选择图片',
            'fileType': 'image/*',
            'fileSizeLimit': 1024,
            'queueSizeLimit': 1,
            'formData': {},
            'queueID': 'img_queue',
            'uploadScript': '${base}/open/file/upload/image',
            'onUploadComplete': function (file, data) {
                data = JSON.parse(data);
                if (data.code == 0) {
                    Toast.success(data.msg);
                    $("#img_img").html("<img src='${AppUploadRoot}" + data.data + "' style='width:150px;height:95px;'>");
                    $("#img").val(data.data);
                } else {
                	img_clearFile();
                    Toast.error(data.msg);
                }
            },
            'onDrop': function (file, fileDropCount) {
            	img_clearFile();
            },
            'onClearQueue': function (queue) {
            	img_clearFile();
            },
            'onCancel': function () {
            	img_clearFile();
            }
        });
        	var dialog=$("#addModal");
    		$("#addModalDialog").draggable();
            $('#addForm').ajaxForm({
                dataType: 'json',
                beforeSubmit: function (arr, form, options) {
                },
                success: function (data, statusText, xhr, form) {
                    if (data.code==0) {
                        Toast.success(data.msg);
                        datatable.ajax.reload();
                        dialog.modal("hide");
                    } else {
                    	Toast.error(data.msg);
                        datatable.ajax.reload();
                        dialog.modal("hide");
                    }
                }
            });
    });
</script>
